Q: How many stacks are required for evaluation of prefix expression?
Solution: 2 stacks are required for evaluation of prefix expression, one for integers and one for characters.
Q: While evaluating a prefix expression, the string is read from?
Solution: The string is read from right to left because a prefix string has operands to its right side.
Q: The associativity of an exponentiation operator ^ is right side.
Solution: The associativity of ^ is right side while the rest of the operators like +,-,*,/ has its associativity to its left.
Q: How many types of input characters are accepted by this algorithm?
Solution: Three kinds of input are accepted by this algorithm- numbers, operators and new line characters.
Q: What determines the order of evaluation of a prefix expression?
Solution: Precedence is a very important factor in determining the order of evaluation. If two operators have the same precedence, associativity comes into action.
Q: Find the output of the following prefix expression. *+2-2 1/-4 2+-5 3 1
Solution: The given prefix expression is evaluated using two stacks and the value is given by (2+2-1)*(4-2)/(5-3+1)= 2.
Q: An error is thrown if the character ‘ ’ is pushed in to the character stack.
Solution: The input character ‘ ’ is accepted as a character by the evaluation of prefix expression algorithm.
Q: Using the evaluation of prefix algorithm, evaluate +-9 2 7.
Solution: Using the evaluation of prefix algorithm, +-9 2 7 is evaluated as 9-2+7=14.
Q: If -*+abcd = 11, find a, b, c, d using evaluation of prefix algorithm.
Solution: The given prefix expression is evaluated as ((1+2)*5)-4 = 11 while a=1, b=2, c=5, d=4.
Q: In the given C snippet, find the statement number that has error. //C code to push an element into a stack 1. void push( struct stack *s, int x) 2. { 3. if(s->top==MAX-1) 4. { 5. printf(“stack overflow”); 6. } 7. else 8. { 9. s->items[++s->top]=x; 10. s++; 11. } 12. }
Solution: If the stack is not full then we are correctly incrementing the top of the stack by doing “++s->top” and storing the value of x in it. However, in the next statement “s++”, we are un-necessarily incrementing the stack base pointer which will lead to memory corruption during the next push() operation.
You Have Score    | /10 |